package com.dcivision.framework.web;

import java.util.Calendar;

import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;

public class ListEventMessageForm extends AbstractSearchForm {
  
  public static final String REVISION = "$Revision: 1.2 $";
  
  /** Holds value of property updateDateFrom.  */
  private String accessDateFrom; 

  /** Holds value of property updateDateTo.  */
  private String accessDateTo;

  /** Holds value of property periodType.   */
  private String periodType = "month";

  /** Holds value of property accessType. */
  private String accessType;
  
  /** Getter for property updateDateFrom.
   * @return Value of property updateDateFrom.
   */
  private String userRecordID = null;
  private String isExport = null; 
  private String clearAll = null;
  
  public String getAccessDateFrom() {
    Calendar cal = Calendar.getInstance();
    if(Utility.isEmpty(periodType)){
      return accessDateFrom;
    }else if("week".equals(periodType)){
      cal.add(Calendar.DATE,1-cal.get(Calendar.DAY_OF_WEEK));
    }else if("month".equals(periodType)){
      cal.set(Calendar.DATE,1);
    }else if("full".equals(periodType)){
      return null;
    }
    cal.set(Calendar.AM_PM, Calendar.AM);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return TextUtility.formatDate(cal.getTime(), SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT));
  }

  /** Setter for property updateDateFrom.
   * @param updateDateFrom New value of property updateDateFrom.
   */
  public void setAccessDateFrom(String accessDateFrom) {
    this.accessDateFrom = accessDateFrom;
  }

  /** Getter for property updateDateTo.
   * @return Value of property updateDateTo.
   */
  public String getAccessDateTo() {
    Calendar cal = Calendar.getInstance();
    if(Utility.isEmpty(periodType)){
      return accessDateTo;
    }else if("week".equals(periodType)){
      cal.add(Calendar.DATE,7-cal.get(Calendar.DAY_OF_WEEK));
    }else if("month".equals(periodType)){
      cal.add(Calendar.MONTH,1);
      cal.set(Calendar.DATE,0);
    }else if("full".equals(periodType)){
      return null;
    }
    cal.set(Calendar.AM_PM, Calendar.PM);
    cal.set(Calendar.HOUR, 11);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);
    return TextUtility.formatDate(cal.getTime(), SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT));
  }

  /** Setter for property updateDateTo.
   * @param updateDateTo New value of property updateDateTo.
   */
  public void setAccessDateTo(String accessDateTo) {
    this.accessDateTo = accessDateTo;
  }

  /** Getter for property periodType.
   * @return Value of property periodType.
   */
  public String getPeriodType() {
    return this.periodType;
  }

  /** Setter for property periodType.
   * @param periodType New value of property periodType.
   */
  public void setPeriodType(String periodType){
    this.periodType = periodType;
  }

  /** Getter for property accessType.
   * @return Value of property accessType.
   */
  public String getAccessType() {
    return this.accessType;
  }

  /** Setter for property accessType.
   * @param accessType New value of property accessType.
   */
  public void setAccessType(String accessType) {
    this.accessType = accessType;
  }

  public String getUserRecordID() {
    return userRecordID;
  }

  public void setUserRecordID(String userRecordID) {
    this.userRecordID = userRecordID;
  }

  public String getIsExport() {
    return isExport;
  } 

  public void setIsExport(String isExport) {
    this.isExport = isExport;
  }

  public String getClearAll() {
    return clearAll;
  }

  public void setClearAll(String clearAll) {
    this.clearAll = clearAll;
  }
}

